package cn.wolfcode.trip.admin.web.controller;

import cn.wolfcode.trip.base.domain.Ticket;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.ITicketService;
import cn.wolfcode.trip.base.service.IViewPointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/ticket")
public class TicketController {

    private final ITicketService ticketService;
    private final IViewPointService viewPointService;

    @Autowired
    public TicketController(ITicketService ticketService, IViewPointService viewPointService) {
        this.ticketService = ticketService;
        this.viewPointService = viewPointService;
    }

    @RequestMapping("/list")
    public String list(@ModelAttribute("qo") QueryObject qo, Model model) {
        //设置按照最后更新时间升序排列
        model.addAttribute("pageInfo", ticketService.queryTickets(qo));
        model.addAttribute("places", viewPointService.getList());
        return "ticket/list";
    }

    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(Ticket entity) {
        ticketService.saveOrUpdate(entity);
        return "redirect:/ticket/list.do";
    }
}
